package com.xio.cloud.contoller;

import com.xio.cloud.domain.CommonResult;
import com.xio.cloud.domain.Storage;
import com.xio.cloud.service.StorageService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: xio
 * @Description: 库存控制层
 * @Date: 2021/3/31 20:59
 */
@RestController
public class StorageController {

    @Resource
    private StorageService storageService;

    @GetMapping("/{id}")
    public Storage get(@PathVariable String id) {
        return storageService.getById(id);
    }

    @GetMapping("/storage/decrease")
    CommonResult decrease(@RequestParam("productId") Long productId,
                          @RequestParam("count") Integer count) {
        return CommonResult.of(storageService.decrease(productId, count),"扣库存成功");
    }

}
